#include<stdio.h>
int main()
{
	int m = 0, n = 0;
	int re = 0;
	scanf_s("%d %d", &m, &n);
	while (re= m % n)
	{
		m = n;
		n = re;
	}
	printf("%d", n);
	return 0;
}
